﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GcmpDatabaseInterface.h"
#include "GbmpGuid.h"
#include <ostream>
#include <string>

namespace gcmp
{
    class GCMP_DATABASE_INTERFACE_EXPORT ClassId
    {
    public:
        ClassId() noexcept : m_guid(GuidUtils::GetInvalid()) {}

        explicit ClassId(const Guid & guid) : m_guid(guid) {}

        // 接受格式为：%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X 的字符串，中间允许有空格。空串或者不符合格式的产生Invalid()的ClassId
        explicit ClassId(const std::wstring & wstr);

        bool operator == (const ClassId & another) const;

        bool operator != (const ClassId & another) const;

        bool operator > (const ClassId & another) const;

        bool operator < (const ClassId & another) const;

        bool IsValid() const;

        // 返回格式为：%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X 的字符串表示
        std::wstring AsWString() const;

        // 接受格式为：%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X 的字符串，中间允许有空格。空串或者不符合格式的产生Invalid()的ClassId
        void SetByWString(const std::wstring & wstr);

        const Guid & GetGuid() const { return m_guid; }

        void SetGuid(const Guid & guid) { m_guid = guid; }

    private:
        Guid m_guid;
    };

    struct GCMP_DATABASE_INTERFACE_EXPORT ClassIdHasher
    {
        std::size_t operator()(const ClassId & key) const;
    };
}

